﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{    
    public partial class JLTVK07Data : BaseFunction
    {
        ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        /*public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }

        SETINTEXDB INTEXDB = new SETINTEXDB();
         */
        public JLTVK07Data()
            : base()
        {
        }
         public JLTVK07Data(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetVK07(DataRow dwTABEL)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "VK07";
            string CO = dwTABEL["CO"].ToString().Trim();
            try
            {
                orlReadCommand = INTEXDBC.OracleDB.CreateCommand();
                orlReadCommand.CommandText = " SELECT A.VKKAUFKRS||'-'||LPAD(TO_NUMBER(A.VKKAUFLFD),4,0) AS CO, "
                    + " (SELECT STRAGG(TRIM(T2.TXTKTEXT)) "
                    + " FROM TXTIND T1,TXTKON T2 "
                    + " WHERE T1.TXTIMANDANT = T2.TXTKMANDANT AND T1.TXTIPIND = T2.TXTKPIND "
                    + " AND T1.TXTITXTART = 'VKT' "
                    + " AND T1.TXTISIND LIKE A.VKKAUFKRS||A.VKKAUFLFD||A.VKKAENDST||'ANGE%') AS PREMARK, "
                    + " (SELECT STRAGG(TRIM(T2.TXTKTEXT)) FROM TXTIND T1,TXTKON T2 "
                    + " WHERE T1.TXTIMANDANT = T2.TXTKMANDANT AND T1.TXTIPIND = T2.TXTKPIND "
                    + " AND T1.TXTITXTART = 'VKT' "
                    + " AND T1.TXTISIND LIKE A.VKKAUFKRS||A.VKKAUFLFD||A.VKKAENDST||'RECH%') AS RREMARK, "
                    + " (SELECT STRAGG(TRIM(T2.TXTKTEXT)) "
                    + " FROM TXTIND T1,TXTKON T2 WHERE T1.TXTIMANDANT = T2.TXTKMANDANT "
                    + " AND T1.TXTIPIND = T2.TXTKPIND AND T1.TXTITXTART = 'VKT' "
                    + " AND T1.TXTISIND LIKE A.VKKAUFKRS||A.VKKAUFLFD||A.VKKAENDST||'LVOR%') AS SREMARK "
                    + " FROM VKKOPF A "
                    + " WHERE A.VKKSA = '  ' "
                    + " AND A.VKKMANDANT = '00' "
                    + " AND A.VKKAUFKRS||'-'||LPAD(TO_NUMBER(A.VKKAUFLFD),4,0) LIKE '"+CO+"%' "
                    + " ORDER BY 1 "
                    ;

                Result = INTEXDBC.Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    byte[] b;
                    string value;
                    foreach (DataRow dw in Result.Tables[TableName].Rows)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["PREMARK"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["PREMARK"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["RREMARK"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["RREMARK"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["SREMARK"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["SREMARK"] = value;

                    }
                }
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        
        public DataSet BuildData(DataRow dwUI)
        {
            /*DataSet SResult = new DataSet();
            SETINTEXDB SReturn = new SETINTEXDB(); */
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetVK07(dwUI);
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

    }
}